﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace codedynamiks_mes_baguio
{
    partial class frmMain
    {
        void InitializeFrameSlider()
        {
            Common.PARENT = this;
            LoadSettings();
            this.Resize += new EventHandler(frmMain_Resize);
            this.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);
            this.Load += new EventHandler(frmMain_Load);
            sldMain.ItemRemoved += new EventHandler(sldMain_ItemRemoved);
            sldMain.ItemAdded += new EventHandler(sldMain_ItemAdded);
            sldMain.AnimationCompleted += new EventHandler(sldMain_AnimationCompleted);
            mnuCloseAll.Click += new EventHandler(mnuCloseAll_Click);
        }
        void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (sldMain.ItemCount > 0)
            {
                string msg = string.Format("There are {0} session(s) running. Are you sure to close the application?", sldMain.ItemCount);
                DialogResult dlg = MessageBox.Show(msg, "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (dlg == DialogResult.No) e.Cancel = true;
            }
        }
        void frmMain_Resize(object sender, EventArgs e)
        {
            sldMain.Width = this.Width - 40;
            sldMain.Height = this.Height - 77;
        }
        void sldMain_ItemRemoved(object sender, EventArgs e)
        {
            string[] buf = sldMain.ItemList;
            mnuWindow.DropDownItems.Clear();
            for (int i = 0; i < buf.Length; i++)
            {
                mnuWindow.DropDownItems.Add((i + 1) + "-" + buf[i], null, new EventHandler(window_Click));
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            if (sldMain.ItemCount > 0) mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
            mnuCloseAll.Text = "Close All Sessions (" + buf.Length + ")";
        }
        void sldMain_ItemAdded(object sender, EventArgs e)
        {
            string[] buf = sldMain.ItemList;
            mnuWindow.DropDownItems.Clear();
            for (int i = 0; i < buf.Length; i++)
            {
                mnuWindow.DropDownItems.Add((i + 1) + "-" + buf[i], null, new EventHandler(window_Click));
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
            mnuCloseAll.Text = "Close All Sessions (" + buf.Length + ")";
        }
        void sldMain_AnimationCompleted(object sender, EventArgs e)
        {
            for (int i = 0; i < mnuWindow.DropDownItems.Count; i++)
            {
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            mnuWindow.DropDownItems[sldMain.SelectedIndex].ForeColor = Color.RoyalBlue;
        }
        void window_Click(object sender, EventArgs e)
        {
            int index = mnuWindow.DropDownItems.IndexOf((ToolStripItem)sender);
            for (int i = 0; i < mnuWindow.DropDownItems.Count; i++)
            {
                mnuWindow.DropDownItems[i].ForeColor = Color.Black;
            }
            sldMain.MoveTo(index);
            mnuWindow.DropDownItems[index].ForeColor = Color.RoyalBlue;
        }
        void mnuCloseAll_Click(object sender, EventArgs e)
        {
            if (sldMain.ItemCount > 0)
            {
                sldMain.Controls.Clear();
            }
        }
        void frmMain_Load(object sender, EventArgs e)
        {

        }
        void LoadSettings()
        {
            frmConfig frm = new frmConfig();
            frm.Initialize("Settings");
            frm = null;
        }
    }
}
